﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;

namespace littleAdminHelper
{
    class script
    {


        private script()
        {
           

        }

        public static Boolean executeVBScript(String path)
        {
            Process process = new Process();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.FileName = "cscript.exe";
            process.StartInfo.Arguments = PathConversion.encodepath(path);


            try
            {
                process.Start();
                if (process.ExitCode == 1)
                {
                    return true;
                }
                else if (process.ExitCode == 2)
                {
                    return false;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception e)
            {
                return false;
            }

        }

        public static Boolean executePowerShellScript(String path)
        {
          
            Process process = new Process();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.FileName = "powershell.exe";
            process.StartInfo.Arguments = PathConversion.encodepath(path);

            try
            {
                process.Start();
                if (process.ExitCode == 1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public static void executeShellScript(String path)
        {

            Process process = new Process();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.FileName = "cmd.exe";
            process.StartInfo.Arguments = PathConversion.encodepath(path);

            try
            {
                process.Start();
            }
            catch (Exception e)
            {
               
            }
        }

        public static void openFileOrURL(String path)
        {
            String relativepath="";
            Process process = new Process();
            try
            {
            
           
               
              
                process.StartInfo.FileName = PathConversion.encodepath(path);
               
                
                process.StartInfo.UseShellExecute = true;
                process.StartInfo.Arguments = "";
                process.Start();
                while (process.HasExited == false)
                {
                        System.Threading.Thread.Sleep(1000);
                }
               
              


            }
            catch (Exception e)
            {
                
            }
        }

        public static void writeToFile(String path)
        {

            Process process = new Process();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.FileName = "cmd.exe";
            process.StartInfo.Arguments = path;

            try
            {
                process.Start();
            }
            catch (Exception e)
            {

            }
        }




        //public static Boolean executeShellScript(String path)
        //{

        //    Process process = new Process();
        //    process.StartInfo.UseShellExecute = false;
        //    process.StartInfo.RedirectStandardOutput = true;
        //    process.StartInfo.FileName = "cmd.exe";
        //    process.StartInfo.Arguments = path;

        //    try
        //    {
        //        process.Start();
        //        if (process.ExitCode == 1)
        //        {
        //            return true;
        //        }
        //        else
        //        {
        //            return false;
        //        }


        //    }
        //    catch (Exception e)
        //    {
        //        return false;
        //    }

        //}
        
        

    }
}
